import time


class Timer:
    def __init__(self, task_name="任务"):
        self.start_time = None
        self.task_name = task_name

    def start(self):
        # 开始计时
        self.start_time = time.time()

    def end(self):
        # 结束计时
        end_time = time.time()

        # 计算任务执行时间
        execution_time = end_time - self.start_time

        # 打印执行时间
        print(f"{self.task_name}执行时间: {execution_time}秒")
        return execution_time


if __name__ == '__main__':
    timer = Timer("test")
    timer.start()

    timer.end()
